package com.zyx.springmvc.reqmap.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author Yaxi.Zhang
 * @since 2021/9/13 15:50
 */
@Controller
/*@RequestMapping("/test")*/
public class RequestMappingController {

    @RequestMapping("/")
    public String index() {
        return "index";
    }

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }

    @RequestMapping("/params")
    public String params() {
        return "params";
    }

    @RequestMapping(
            value = {"/test", "/testRequestMapping"},
            method = {RequestMethod.GET, RequestMethod.POST},
            params = {"username", "password!=123456"}
    )
    public String testParam() {
        return "success";
    }

    @RequestMapping(
            value = {"/testParamAndHeader"},
            params = {"username", "password!=123456"},
            headers = {"Host=localhost:8080"}
    )
    public String testParamAndHeader() {
        return "success";
    }

    @RequestMapping(
            value = "/**/testAnt"
    )
    public String testAnt() {
        return "success";
    }

    @RequestMapping(
            value = "/testPath/{id}/{username}"
    )

    public String testPath(@PathVariable(value = "id") String id, @PathVariable(value = "username") String username) {
        System.out.println("id: " + id + ",username: " + username);
        return "success";
    }

}
